/**
 * 登录
 */
var React = require("react");
var {Modal,Button,Form,FormGroup,ControlLabel,Col} = require("react-bootstrap");
var {Util,FormPage,RedStar} = require("flower");
class Login extends FormPage{
    constructor(props){
        super(props);
        this.state = {
            show:true
        };
    }

    componentDidMount(){
        var that = this;
        $("body").bind("keypress", function(event){
            if (event.keyCode == 13) {
                that.login();
            }
        });

    }

    login(){
        var data = this.getFormData();
        var ret = Util.post("/doLogin",data);
        if(ret.state == 1){
            window.location.href = Util.basePath() + "/main";
        }else{
            alert(ret.msg);
        }
    }

    close(){
        this.setState({
            show:false
        });
    }

    render(){
        return <div>
            <Modal show={this.state.show}>
                <Modal.Header closeButton>
                    <Modal.Title>登录</Modal.Title>
                </Modal.Header>
                <Modal.Body>
                    <Form horizontal>
                        <FormGroup>
                            <Col componentClass={ControlLabel} sm={2}>
                                用户名<RedStar/>
                            </Col>
                            <Col sm={8}>
                                <input className="form-control" placeholder="请输入用户名" ref="name" />
                            </Col>
                        </FormGroup>

                        <FormGroup>
                            <Col componentClass={ControlLabel} sm={2}>
                                密码<RedStar/>
                            </Col>
                            <Col sm={8}>
                                <input type="password" className="form-control" placeholder="请输入密码" ref="pwd"/>
                            </Col>
                        </FormGroup>
                    </Form>
                </Modal.Body>
                <Modal.Footer>
                    <Button bsStyle="primary" onClick={this.login.bind(this)}>登录</Button>
                    <Button onClick={this.close.bind(this)}>取消</Button>
                </Modal.Footer>
            </Modal>
        </div>
    }
}

module.exports = Login;